package com.zmn.oms.business.impl.warningnews;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.zmn.base.engineer.common.constants.DubboConsts;
import com.zmn.base.engineer.common.dro.foreign.engineer.ForeignEngineerBasicInfoDRO;
import com.zmn.base.engineer.dubbo.interfaces.foreign.EngineerListRemoteService;
import com.zmn.base.plat.engine.common.util.response.DubboResponseUtils;
import com.zmn.base.remind.common.consts.MqConst;
import com.zmn.base.remind.common.enums.AppTypeEnum;
import com.zmn.base.remind.common.enums.ScenesTypeEnum;
import com.zmn.base.remind.common.model.remind.RemindRequestDIO;
import com.zmn.base.remind.common.model.remind.VoiceVariateDIO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.consts.GlobalConsts;
import com.zmn.framework.mq.ZmnMQException;
import com.zmn.manager.mq.constant.MqTopicConsts;
import com.zmn.manager.mq.interfaces.ZmnMQSender;
import com.zmn.oms.business.interfaces.log.OrderLogBService;
import com.zmn.oms.business.interfaces.messageV1.common.MessageSendBaseService;
import com.zmn.oms.business.interfaces.warningnews.OmsOrderWarningNewsBService;
import com.zmn.oms.common.constant.MessageQueueTagConsts;
import com.zmn.oms.common.constant.MessageRuleIdConsts;
import com.zmn.oms.common.constant.OrderLogConsts;
import com.zmn.oms.common.enums.RedistributeStatusEnum;
import com.zmn.oms.constant.MessageQueueTopicConstant;
import com.zmn.oms.model.dto.messageV1.AppMessageDTO;
import com.zmn.oms.model.entity.detail.OrderDetail;
import com.zmn.oms.model.entity.log.OrderLog;
import com.zmn.oms.model.entity.masterworking.MasterWorking;
import com.zmn.oms.model.entity.redistribute.OrderWorkRedistributeApply;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.services.interfaces.detail.OrderDetailService;
import com.zmn.oms.services.interfaces.masterworking.MasterWorkingService;
import com.zmn.oms.services.interfaces.redistribute.OrderWorkRedistributeApplyService;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import com.zmn.performance.common.constant.OrderTimeoutConsts;
import com.zmn.performance.common.enums.BizTypeEnum;
import com.zmn.performance.common.enums.OrderWarningTypeEnum;
import com.zmn.performance.common.enums.conf.timeout.ConfigName;
import com.zmn.performance.common.enums.conf.timeout.ConfigNodeType;
import com.zmn.performance.common.enums.conf.timeout.ConfigType;
import com.zmn.performance.dubbo.interfaces.order.OrderTimeoutWarningListRemoteService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 类描述：预警或超时消息业务处理
 *
 * @author yangshuangping
 * @since 2022/06/23 13:45
 */
@Slf4j
@Service
public class OmsOrderWarningNewsBServiceImpl implements OmsOrderWarningNewsBService {

    private static final int WARNING_TYPE = 1;
    private static final int TIME_OUT_TYPE = 2;

    /**
     * 发送消息服务
     */
    @Resource
    private MessageSendBaseService messageSendBaseService;

    /**
     * 保存订单日志服务
     */
    @Resource
    private OrderLogBService orderLogBService;
    /**
     * 订单服务
     */
    @Resource
    private OrderDetailService orderDetailService;

    /**
     * 工单服务
     */
    @Resource
    private OrderWorkService orderWorkService;
    /**
     * 订单改派服务
     */
    @Resource
    private OrderWorkRedistributeApplyService orderWorkRedistributeApplyService;

    /**
     * 订单取消服务
     */
    @Resource
    private MasterWorkingService masterWorkingService;
    /**
     * mq消息服务
     */
    @Resource
    private ZmnMQSender zmnMQSender;

    @NacosValue(value = "${warningNews.sendWithDelayTime:3}", autoRefreshed = true)
    private Integer messageDelayTime;

    /**
     * 工程师服务
     */
    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false,timeout =100000 )
    private EngineerListRemoteService engineerListRemoteService;

    @DubboReference(version = com.zmn.base.plat.engine.common.constant.DubboConsts.INTERFACE_VERSION, check = false)
    private OrderTimeoutWarningListRemoteService orderTimeoutWarningListRemoteService;

    @Override
    public void timeOutNoticeSaveOrderLogAndSendAppPush(Long workId, Long orderId, Integer timeoutType) {
        List<Integer> timeOutTypeList = IntStream.of(OrderTimeoutConsts.TIME_OUT_TYPE_CONTACT, OrderTimeoutConsts.TIME_OUT_TYPE_TAKE, OrderTimeoutConsts.TIME_OUT_TYPE_VISIT, OrderTimeoutConsts.TIME_OUT_TYPE_COMPLETE).boxed().collect(Collectors.toList());
        // 除这个几个状态需要走流程
        if (timeOutTypeList.contains(timeoutType)) {
            OrderWork work = orderWorkService.findOrderWorkByKey(orderId, workId);
            //保存工单日志
            saveOrderLog(workId, orderId, timeoutType, TIME_OUT_TYPE);
            // 判断工单状态是否是待取消或待改派
            final Boolean orderStatus = checkOrderStatusWaitCancelAndWaitRedistribute(workId, orderId);
            log.info("#omsOrderWarningNewsBService# 步骤2,orderId：{},订单超时判断该工单是否是待取消或待改派orderStatus：{}", orderId, orderStatus);
            if (Boolean.FALSE.equals(orderStatus)) {
                // 发送APP消息
                sendAppPushMessage(work, timeoutTypeAppPushCode(timeoutType));
                // 10 分钟后拍断是否已经改了状态
                String key = String.format("timeOutNotice_%s_%s_%s", workId, orderId, timeoutType);
                JSONObject message = new JSONObject();
                message.put("timeoutType", timeoutType);
                message.put("orderWork", work);
                String content = JSON.toJSONString(message);
                long time = System.currentTimeMillis() + messageDelayTime * 1000;
                zmnMQSender.sendWithStartDeliverTime(MqTopicConsts.ZMN_TOPIC_OMS, MessageQueueTagConsts.ORDER_WORK_TIME_OUT_NOTICE_TAG, key, content, time);
                log.info("#omsOrderWarningNewsBService# 步骤4,orderId：{},订单超时发送延迟MQ消息：key:[{}],message=>{}", orderId, key, content);
            }
        }
    }

    @Override
    public void warningNoticeSaveOrderLogAndSendAppPush(Long workId, Long orderId, Integer warningType) {
        List<Integer> warningTypeList = IntStream.of(OrderWarningTypeEnum.TAKE.getCode(), OrderWarningTypeEnum.CONTACT.getCode(), OrderWarningTypeEnum.VISIT.getCode(), OrderWarningTypeEnum.COMPLETE.getCode()).boxed().collect(Collectors.toList());
        if (warningTypeList.contains(warningType)) {
            OrderWork work = orderWorkService.findOrderWorkByKey(orderId, workId);
            //保存工单日志
            saveOrderLog(workId, orderId, warningType, WARNING_TYPE);
            // 判断工单状态是否是待取消或待改派
            final Boolean orderStatus = checkOrderStatusWaitCancelAndWaitRedistribute(workId, orderId);
            log.info("#omsOrderWarningNewsBService# 步骤2,orderId：{} 订单预警判断该工单是否是待取消或待改派orderStatus：{}", orderId, orderStatus);
            if (Boolean.FALSE.equals(orderStatus)) {
                // 发送APP消息
                sendAppPushMessage(work, warningNoticeAppPushCode(warningType));
                // 10 分钟后拍断是否已经改了状态
                String key = String.format("warningNotice_%s_%s_%s", workId, orderId, warningType);
                JSONObject message = new JSONObject();
                message.put("timeoutType", warningType);
                message.put("orderWork", work);
                String content = JSON.toJSONString(message);
                long time = System.currentTimeMillis() + messageDelayTime * 1000;
                zmnMQSender.sendWithStartDeliverTime(MqTopicConsts.ZMN_TOPIC_OMS, MessageQueueTagConsts.ORDER_WORK_WARNING_NOTICE_TAG, key, content, time);
                log.info("#omsOrderWarningNewsBService# 步骤4,orderId：{} 订单预警发送延迟MQ消息：key:[{}],message=>{}", orderId, key, content);
            }
        }
    }

    @Override
    public void timeOutNoticeRobotNotice(OrderWork oldOrderWork, Integer timeoutType) {
        OrderWork work = orderWorkService.findOrderWorkByKey(oldOrderWork.getOrderId(), oldOrderWork.getWorkId());
        final boolean orderWorkStatus = Objects.equals(oldOrderWork.getStatus(), work.getStatus());

        // 如果状态发生变化则不需要机器人打电话通知
        if (Boolean.FALSE.equals(orderWorkStatus)) {
            return;
        }
        // 领单超时 上门超时 完成超时
        final boolean takeAndVisit = Objects.equals(OrderTimeoutConsts.TIME_OUT_TYPE_TAKE, timeoutType) || Objects.equals(OrderTimeoutConsts.TIME_OUT_TYPE_VISIT, timeoutType) || Objects.equals(OrderTimeoutConsts.TIME_OUT_TYPE_COMPLETE, timeoutType);
        if (takeAndVisit) {
            robotCall(work, TIME_OUT_TYPE, timeoutType);
        }
        // 联系超时
        final boolean contact = Objects.equals(OrderTimeoutConsts.TIME_OUT_TYPE_CONTACT, timeoutType) && Objects.isNull(work.getContactTime());
        if (contact) {
            robotCall(work, TIME_OUT_TYPE, timeoutType);
        }
    }

    @Override
    public void warningNoticeRobotNotice(OrderWork oldOrderWork, Integer timeoutType) {
        OrderWork work = orderWorkService.findOrderWorkByKey(oldOrderWork.getOrderId(), oldOrderWork.getWorkId());
        final boolean orderWorkStatus = Objects.equals(oldOrderWork.getStatus(), work.getStatus());
        // 如果状态发生变化则不需要机器人打电话通知
        if (Boolean.FALSE.equals(orderWorkStatus)) {
            return;
        }
        // 领单超时 上门超时
        final boolean takeAndVisit = Objects.equals(OrderWarningTypeEnum.TAKE.getCode(), timeoutType) || Objects.equals(OrderWarningTypeEnum.VISIT.getCode(), timeoutType);
        if (takeAndVisit) {
            robotCall(work, WARNING_TYPE, timeoutType);
        }
        // 联系超时
        final boolean contact = Objects.equals(OrderWarningTypeEnum.CONTACT.getCode(), timeoutType) && Objects.isNull(work.getContactTime());
        if (contact) {
            robotCall(work, WARNING_TYPE, timeoutType);
        }
    }

    /**
     * 保存日志
     *
     * @param workId      工单ID
     * @param orderId     订单ID
     * @param messageType 超时，预警类型
     * @param type        1：预警 2：超时
     */
    private void saveOrderLog(Long workId, Long orderId, Integer messageType, Integer type) {
        OrderLog orderLog = new OrderLog();
        orderLog.setWorkId(workId);
        orderLog.setOrderId(orderId);
        if (Objects.equals(type, TIME_OUT_TYPE)) {
            orderLog.setContent(String.format("工程师%s", timeOutNoticeTypeName(messageType)));
            orderLog.setTypeName(timeOutNoticeTypeName(messageType));
            orderLog.setType(OrderLogConsts.ORDER_LOG_TYPE_TIME_OUT_NOTICE);

        }
        if (Objects.equals(type, WARNING_TYPE)) {
            orderLog.setContent(String.format("工程师%s%s即将超时", warningNoticeTypeName(messageType), Objects.equals(OrderWarningTypeEnum.CONTACT.getCode(), messageType) ? "用户" : ""));
            orderLog.setTypeName(String.format("%s预警", warningNoticeTypeName(messageType)));
            orderLog.setType(OrderLogConsts.ORDER_LOG_TYPE_WARNING_NOTICE);
        }
        orderLog.setCreateTime(DateUtil.getNow());
        orderLog.setOperator("系统");
        orderLog.setOperatorType(GlobalConsts.OPERATE_USER_TYPE_SYSTEM);
        orderLog.setOperatorTypeName("系统");
        orderLog.setOperatorId(1L);
        orderLogBService.save(orderLog);
        log.info("#omsOrderWarningNewsBService# 步骤1,orderId：{} 预警或超时发送保存日志信息", orderId);

    }

    /**
     * 根据超时类型转换为中文
     *
     * @param timeoutType 超时类型
     * @return java.lang.String
     */
    private String timeOutNoticeTypeName(Integer timeoutType) {
        if (NumberUtil.isNullOrZero(timeoutType)) {
            return "";
        }
        switch (timeoutType) {
            case OrderTimeoutConsts.TIME_OUT_TYPE_CONTACT:
                return "联系超时";
            case OrderTimeoutConsts.TIME_OUT_TYPE_TAKE:
                return "领单超时";
            case OrderTimeoutConsts.TIME_OUT_TYPE_VISIT:
                return "上门超时";
            case OrderTimeoutConsts.TIME_OUT_TYPE_COMPLETE:
                return "完成超时";
            default:
                return "";
        }

    }

    /**
     * 根据预警类型转换为中文
     *
     * @param timeoutType 超时类型
     */
    private String warningNoticeTypeName(Integer timeoutType) {
        if (NumberUtil.isNullOrZero(timeoutType)) {
            return "";
        }
        if (Objects.equals(OrderWarningTypeEnum.TAKE.getCode(), timeoutType)) {
            return OrderWarningTypeEnum.TAKE.getDesc();
        }
        if (Objects.equals(OrderWarningTypeEnum.CONTACT.getCode(), timeoutType)) {
            return OrderWarningTypeEnum.CONTACT.getDesc();
        }
        if (Objects.equals(OrderWarningTypeEnum.VISIT.getCode(), timeoutType)) {
            return OrderWarningTypeEnum.VISIT.getDesc();
        }
        if (Objects.equals(OrderWarningTypeEnum.COMPLETE.getCode(), timeoutType)) {
            return OrderWarningTypeEnum.COMPLETE.getDesc();
        }
        return "";
    }

    /**
     * 判断工单是否是待取消或待改派
     *
     * @param workId  工单ID
     * @param orderId 订单ID
     * @return java.lang.Boolean
     */
    private boolean checkOrderStatusWaitCancelAndWaitRedistribute(Long workId, Long orderId) {
        Integer waitRedistributeStatus = RedistributeStatusEnum.WAIT_REDISTRIBUTE.getCode();
        OrderWorkRedistributeApply waitRedistribute = orderWorkRedistributeApplyService.selectByOrderIdAndWorkIdAndRedistributeStatus(orderId, workId, waitRedistributeStatus);
        if (Objects.nonNull(waitRedistribute)) {
            return Boolean.TRUE;
        }
        final MasterWorking waitCancel = masterWorkingService.findMasterWorkingByWorkId(workId);
        if (Objects.nonNull(waitCancel) && Objects.equals(waitCancel.getWaitCancel(), GlobalConsts.YES)) {
            return Boolean.TRUE;
        }
        return false;
    }

    /**
     * 发送APP push 消息
     *
     * @param work     工单ID
     * @param ruleCode code
     */
    private void sendAppPushMessage(OrderWork work, String ruleCode) {
        OrderDetail orderDetail = orderDetailService.findOrderDetailByKey(work.getOrderId());
        if (Objects.nonNull(orderDetail)) {
            JSONObject params = new JSONObject();
            params.put("product_name", orderDetail.getProductInfo());
            params.put("order_id", work.getOrderId());
            this.getMessageDelayTime(params, ruleCode);
            AppMessageDTO appMessage = new AppMessageDTO();
            appMessage.setOrderId(work.getOrderId());
            appMessage.setPlat(work.getPlatWork());
            appMessage.setMasterIdList(Collections.singletonList(work.getMasterId()));
            appMessage.setRuleCode(ruleCode);
            appMessage.setParams(params.toJSONString());
            boolean sendAppPushMessageStatus = messageSendBaseService.batchSendAndroidAndIOSMessage(appMessage);
            log.info("#omsOrderWarningNewsBService# 步骤3,orderId：{} 预警或超时发送APP_PUSH消息：sendAppPushMessageStatus:{} appMessage：{}", work.getOrderId(), sendAppPushMessageStatus, JSON.toJSONString(appMessage));
        }
    }

    /**
     * 计算多少分钟内上门
     *
     * @param params   params
     * @param ruleCode ruleCode
     */
    private void getMessageDelayTime(JSONObject params, String ruleCode) {
        if (Objects.equals(MessageRuleIdConsts.PUSH_MSG_TIME_OUT_TYPE_TAKE, ruleCode)) {
            Integer before = Optional.ofNullable(DubboResponseUtils.resultToNull(() -> orderTimeoutWarningListRemoteService.getTimeoutWarningConfig(ConfigNodeType.TAKE, ConfigType.TIMEOUT, BizTypeEnum.C, ConfigName.OVER_DUTY_TIME))).orElse(0);
            Integer after = Optional.ofNullable(DubboResponseUtils.resultToNull(() -> orderTimeoutWarningListRemoteService.getTimeoutWarningConfig(ConfigNodeType.TAKE, ConfigType.TIMEOUT, BizTypeEnum.C, ConfigName.AFTER_DUTY_TIME))).orElse(0);
            int time = after - before;
            params.put("time", Objects.isNull(time) ? "" : time);
        }
    }

    /**
     * 获取超时APP push code
     *
     * @param timeoutType 超时信息类型
     */
    private String timeoutTypeAppPushCode(Integer timeoutType) {
        String appPushCode = "";
        switch (timeoutType) {
            case OrderTimeoutConsts.TIME_OUT_TYPE_CONTACT:
                appPushCode = MessageRuleIdConsts.PUSH_MSG_CALL_OUT_STATUS_ALERT;
                break;
            case OrderTimeoutConsts.TIME_OUT_TYPE_TAKE:
                appPushCode = MessageRuleIdConsts.PUSH_MSG_TIME_OUT_TYPE_TAKE;
                break;
            case OrderTimeoutConsts.TIME_OUT_TYPE_VISIT:
                appPushCode = MessageRuleIdConsts.PUSH_MSG_TIME_OUT_TYPE_VISIT;
                break;
            case OrderTimeoutConsts.TIME_OUT_TYPE_COMPLETE:
                appPushCode = MessageRuleIdConsts.PUSH_MSG_TIME_OUT_TYPE_COMPLETE;
                break;
            default:
        }
        return appPushCode;
    }

    /**
     * 获取预警APP push code
     *
     * @param timeoutType 预警信息类型
     */
    private String warningNoticeAppPushCode(Integer timeoutType) {
        if (Objects.equals(OrderWarningTypeEnum.TAKE.getCode(), timeoutType)) {
            return MessageRuleIdConsts.PUSH_MSG_WARNING_NOTICE_TAKE;
        }
        if (Objects.equals(OrderWarningTypeEnum.CONTACT.getCode(), timeoutType)) {
            return MessageRuleIdConsts.PUSH_MSG_WARNING_NOTICE_CONTACT;
        }
        if (Objects.equals(OrderWarningTypeEnum.VISIT.getCode(), timeoutType)) {
            return MessageRuleIdConsts.PUSH_MSG_WARNING_NOTICE_VISIT;
        }
        if (Objects.equals(OrderWarningTypeEnum.COMPLETE.getCode(), timeoutType)) {
            return MessageRuleIdConsts.PUSH_MSG_WARNING_NOTICE_COMPLETE;
        }
        return "";
    }

    /**
     * 机器人拨打电话通知工程师
     *
     * @param work    订单信息
     * @param type    类型：
     *                WARNING_TYPE: 1 预警
     *                TIME_OUT_TYPE: 2 超时
     * @param megType 消息类型
     *                超时类型
     *                OrderTimeoutConsts.TIME_OUT_TYPE_CONTACT 联系超时  5
     *                OrderTimeoutConsts.TIME_OUT_TYPE_TAKE 领单超时  4
     *                OrderTimeoutConsts.TIME_OUT_TYPE_VISIT 上门超时  6
     *                预警类型
     *                OrderWarningTypeEnum.TAKE.getCode() 领单预警 4
     *                OrderWarningTypeEnum.CONTACT.getCode() 联系预警 5
     *                OrderWarningTypeEnum.VISIT.getCode() 上门预警 6
     */
    private void robotCall(OrderWork work, int type, Integer megType) {
        String bizCallId = String.format("%s%d%d", Objects.equals(TIME_OUT_TYPE, type) ? "timeOutNotice_" : "warningNotice_", megType, work.getWorkId());
        final ForeignEngineerBasicInfoDRO basicInfo = DubboResponseUtils.resultToNull(() -> engineerListRemoteService.getEngineerById(work.getMasterId()));
        if (Objects.isNull(basicInfo) || Strings.isBlank(basicInfo.getMobile())) {
            return;
        }
        RemindRequestDIO remindRequest = new RemindRequestDIO();
        remindRequest.setAppId(AppTypeEnum.OMS.getCode());
        remindRequest.setScenesType(robotCallScenesTypeCode(type, megType));
        remindRequest.setBizId(String.valueOf(work.getWorkId()));
        remindRequest.setBizCallId(bizCallId);
        remindRequest.setPhone(basicInfo.getMobile());
        remindRequest.setOperator("系统");
        List<VoiceVariateDIO> variates = new ArrayList<>();
        VoiceVariateDIO voiceVariate = new VoiceVariateDIO();
        voiceVariate.setVariateName("${orderId}");
        voiceVariate.setVariateText(String.valueOf(work.getOrderId()));
        variates.add(voiceVariate);
        remindRequest.setVariates(variates);
        // 30秒后没有打电话就放弃
        remindRequest.setExpireDuration(30);
        String content = JSON.toJSONString(remindRequest);
        try {
            // 发送异步消息队列
            zmnMQSender.sendSync(MessageQueueTopicConstant.ZMN_TOPIC_REMIND, MqConst.REMIND_REQUEST_TAG, bizCallId, content);
            log.info("#omsOrderWarningNewsBService# 步骤5,orderId：{} 超时或预警调用机器人拨打电话提醒工程师成功 bizCallId：{}", work.getOrderId(), bizCallId);
        } catch (ZmnMQException e) {
            log.error("#omsOrderWarningNewsBService# 步骤5,orderId：{} 超时或预警调用机器人拨打电话提醒工程师失败 错误信息：{},业务ID：{}", work.getOrderId(), e.getMessage(), bizCallId);
        }
    }

    /**
     * 获取机器人场景code
     *
     * @param type    类型：
     *                WARNING_TYPE: 1 预警
     *                TIME_OUT_TYPE: 2 超时
     * @param megType 消息类型
     *                超时类型
     *                OrderTimeoutConsts.TIME_OUT_TYPE_CONTACT 联系超时  5
     *                OrderTimeoutConsts.TIME_OUT_TYPE_TAKE 领单超时  4
     *                OrderTimeoutConsts.TIME_OUT_TYPE_VISIT 上门超时  6
     *                预警类型
     *                OrderWarningTypeEnum.TAKE.getCode() 领单预警 4
     *                OrderWarningTypeEnum.CONTACT.getCode() 联系预警 5
     *                OrderWarningTypeEnum.VISIT.getCode() 上门预警 6
     * @return java.lang.Integer
     */
    private Integer robotCallScenesTypeCode(Integer type, Integer megType) {
        // 预警消息
        if (Objects.equals(type, WARNING_TYPE)) {
            if (Objects.equals(OrderWarningTypeEnum.TAKE.getCode(), megType)) {
                // 领单预警
                return ScenesTypeEnum.TAKE_WARNING.getCode();
            } else if (Objects.equals(OrderWarningTypeEnum.CONTACT.getCode(), megType)) {
                // 联系预警
                return ScenesTypeEnum.CONTACT_WARNING.getCode();
            } else if (Objects.equals(OrderWarningTypeEnum.VISIT.getCode(), megType)) {
                // 上门预警
                return ScenesTypeEnum.VISIT_WARNING.getCode();
            } else if (Objects.equals(OrderWarningTypeEnum.COMPLETE.getCode(), megType)) {
                // 完成预警
                return ScenesTypeEnum.FINNISH_WARNING.getCode();
            }
        }
        // 超时消息
        if (Objects.equals(type, TIME_OUT_TYPE)) {
            if (Objects.equals(OrderTimeoutConsts.TIME_OUT_TYPE_CONTACT, megType)) {
                // 联系超时
                return ScenesTypeEnum.CONTACT_TIME_OUT.getCode();
            } else if (Objects.equals(OrderTimeoutConsts.TIME_OUT_TYPE_TAKE, megType)) {
                // 领单超时
                return ScenesTypeEnum.TAKE_TIME_OUT.getCode();
            } else if (Objects.equals(OrderTimeoutConsts.TIME_OUT_TYPE_VISIT, megType)) {
                // 上门超时
                return ScenesTypeEnum.VISIT_TIME_OUT.getCode();
            } else if (Objects.equals(OrderTimeoutConsts.TIME_OUT_TYPE_COMPLETE, megType)) {
                // 完成超时
                return ScenesTypeEnum.FINNISH_TIME_OUT.getCode();
            }
        }
        return GlobalConsts.NONE;
    }
}
